package logic

import (
	"context"
	"doctor/models/mysql"
	"fmt"

	"doctor/doctorrpc/doctorrpc"
	"doctor/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorShowLogic {
	return &DoctorShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorShowLogic) DoctorShow(in *doctorrpc.DoctorShowRequest) (*doctorrpc.DoctorShowResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor

	err := mysql.DB.Debug().Where("id = ?", in.Id).Find(&doctor).Error

	if err != nil {
		return nil, fmt.Errorf("查找失败")
	}

	return &doctorrpc.DoctorShowResponse{
		Name:        doctor.Name,
		HeadImage:   doctor.HeadImage,
		Address:     doctor.Address,
		DoctorName:  doctor.DoctorName,
		RoomAddress: doctor.RoomAddress,
		Count:       doctor.Count,
	}, nil
}
